#!/usr/bin/env python
# -*- coding: utf-8 -*-

def model_to_dict(model) -> dict:
    """将 SQLAlchemy 的模型对象（model）转换为 Python 字典"""
    if model is None:
        return {}

    try:
        columns = model.__table__.columns
    except AttributeError:
        return {}

    return {column.name: getattr(model, column.name) for column in columns}